<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义迭代器遍历</title>
</head>
<script>
    const banji = {
        name:'终极一班',
        stus:['小明','小华','小李','小郑'],
        //自定义迭代器遍历
        [Symbol.iterator](){
            let index = 0
            let _this = this
            return {
                next: function() {
                    if(index < _this.stus.length){
                        const result = {value:_this.stus[index],done: false}
                        index++
                        return result
                    }else{
                        return {value:undefined,done: true}
                    }
                }
            }
        }
    }
    //遍历banji数组的元素值
    for (const v of banji) {
        console.log(v)
    }
</script>
</html>